package com.eastfair.venueservice.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.eastfair.boot.service.SuperServiceImpl;
import com.eastfair.constant.BusinessConstant;
import com.eastfair.core.base.R;
import com.eastfair.core.context.ContextUtil;
import com.eastfair.venueservice.dao.ServicePriceListDetailMapper;
import com.eastfair.venueservice.dto.ServicePriceListDetailDTO;
import com.eastfair.venueservice.entity.ServicePriceListDetail;
import com.eastfair.venueservice.service.ServicePriceListDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
/**
 * <p>
 * 业务实现类
 * 服务价目信息明细表
 * </p>
 *
 * @author linan
 * @date 2022-07-21
 */
@Slf4j
@Service
public class ServicePriceListDetailServiceImpl extends SuperServiceImpl<ServicePriceListDetailMapper, ServicePriceListDetail> implements ServicePriceListDetailService {


    /**
     * 处理逻辑删除相关处理
     *
     * @param modelList 实体
     * @return 是否成功
     */
    @Override
    protected R<Boolean> handlerRemoveByIdsOfLogic(Collection<ServicePriceListDetail> modelList) {
        modelList.stream().forEach(s -> {
            s.setIsDeleted(BusinessConstant.YES);
        });
        // TODO: 2021/10/29 这里需要操作其他业务，如清空角色等
        return R.successDef();
    }


    @Override
    protected R<Boolean> handlerSave(ServicePriceListDetail model) {
        model.setProjectId(ContextUtil.getProjectId());
        model.setSubsystemId(ContextUtil.getSubSystemId());
        model.setTenantId(ContextUtil.getTenantId());
        return R.successDef();
    }

    @Override
    public Boolean updatePriceListDetail(List<ServicePriceListDetailDTO> servicePriceListDetails) {
        for (ServicePriceListDetailDTO servicePriceListDetail : servicePriceListDetails) {
            ServicePriceListDetail detail = BeanUtil.copyProperties(servicePriceListDetail, ServicePriceListDetail.class);
            updateById(detail);
        }
        return true;
    }
}
